#!/bin/bash

if [ $# != 1 ]; then
	echo -e "Usage:\n    \033[33m    $0  <dir>\033[0m"
	exit  -1
fi

path=$1

# 使用[ -d ]来判断目录是否存在
if [ -d "$path" ]; then
	echo $1
    echo -e "\033[36m     ----Directory exists.\033[0m"
else
    echo -e "\033[31m Directory $path does not exist.\033[0m"
    exit -1
fi


# 找到 gbk编码的文件(.o .bin .img等文件除外), 再用 iconv 转为 utf-8 编码
find $path -type f ! -regex ".*\.o\|.*\.bin\|.*\.img\|.*\.map" \
-exec file -i "{}" \; | grep charset=iso | awk -F: '{print $1}' | xargs -I {} \
sh -c 'echo -n "\033[36m {} \033[0m"; iconv -f gbk -t utf-8 {} -o "{}.utf8" && mv "{}.utf8" {} && echo " iconv OK."'


